package com.wyd.resourcetj.dao;

import java.util.Date;

import javax.transaction.Transactional;

import com.wyd.resourcetj.model.Consume_Log;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * IConsume_LogDao
 */
public interface IConsume_LogDao extends JpaRepository<Consume_Log, Integer>,JpaSpecificationExecutor<Consume_Log> {

    /* @Transactional
    @Modifying
   // @Query("update Users u set u.uname = ?2 where u.uid= ?1")  示例
    @Query("update Consume_Log c set c.exist = :exist where c.id= :id")
    
    int deleteConsume_Log(Integer id,Integer exist); */


    //根据卡号修改离开时间
   /*  @Transactional
    @Modifying
   // @Query("update Users u set u.uname = ?2 where u.uid= ?1")  示例
    @Query("update Consume_Log c set c.out_time = :out_time where c.card_no= :card_no")
    
    int updateOutTime(String card_no,Date out_time); */

//根据卡号查询日志
    @Transactional
    @Modifying
    @Query("select  c from  Consume_Log c where c.card_no= :card_no")  

    
    
    Consume_Log findOne(String card_no );    //仅限数据库就该卡号的一条数据！！！待优化！！！


 //查询会员最后一次进入资源室的日志编号
 @Query(value = "select * from consume_log where in_time = (select max(in_time) from consume_log where card_no = :card_no)",nativeQuery = true)
 Consume_Log getMaxInTime(String card_no);




 //更新离开时间
 @Modifying//更新操作
 @Transactional
 @Query(value = "update consume_log c set c.out_time= :outTime where c.id = :id",nativeQuery = true)
 int updateOutTime(int id,Date outTime);
    









}